package com.ryenlii.datatrans.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ryenlii.datatrans.common.model.RequestModel;
import com.ryenlii.datatrans.core.Result;
import com.ryenlii.datatrans.core.ResultGenerator;
import com.ryenlii.datatrans.entity.dto.DeviceRecordDto;
import com.ryenlii.datatrans.entity.DeviceRecord;
import com.ryenlii.datatrans.service.DeviceRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备推送信息管理
 *
 * @author zhengwen
 * @since 2023-02-03
 */
@RestController
@RequestMapping("/deviceRecord")
@RequiredArgsConstructor
public class DeviceRecordController {

    private final DeviceRecordService deviceRecordService;

    /**
     * 列表
     *
     * @param requestModel 条件对象
     * @return 统一出参
     */
    @PostMapping("/getPage")
    public Result<?> selectPage(@RequestBody RequestModel<DeviceRecord> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<DeviceRecordDto> record = deviceRecordService.selectPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return ResultGenerator.genSuccessResult(record);
    }

    /**
     * 使用join查询列表
     *
     * @param requestModel 条件对象
     * @return 统一出参
     */
    @PostMapping("/getPageUseJoin")
    public Result<?> getPageUseJoin(@RequestBody RequestModel<DeviceRecord> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<DeviceRecordDto> record = deviceRecordService.getPageUseJoin(requestModel.getPage(), requestModel.getCustomQueryParams());
        return ResultGenerator.genSuccessResult(record);
    }
}
